package com.wish.wishsystem_management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.wishsystem_management.entity.SysRole;
import com.wish.wishsystem_management.entity.SysRoleDept;
import com.wish.wishsystem_management.entity.SysRoleMenu;
import com.wish.wishsystem_management.mapper.SysRoleDeptMapper;
import com.wish.wishsystem_management.service.ISysRoleDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色与部门对应关系 服务实现类
 * </p>
 *
 * @author zhaiwj
 * @since 2021-03-22
 */
@Service
public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDept> implements ISysRoleDeptService {
    /**
     * 根据角色id删除中间表
     */
    @Override
    public void deleteByRoleId(Long roleId) {
        baseMapper.deleteByRoleId(roleId);
    }

    //部门下的角色表
    @Override
    public List<SysRole> queryListByDeptId(Long deptId) {
        return baseMapper.queryListByDeptId(deptId);
    }

    /**
     * 根据角色ID，获取部门ID列表
     */
    @Override
    public List<Long> queryDeptIdList(Long roleId) {
        return baseMapper.queryDeptIdList(roleId);
    }

    /**
     * 保存角色部门中间表
     */
    @Override
    public void saveDeptRole(SysRole sysRole) {
        baseMapper.saveDeptRole(sysRole);
    }

    /**
     * 修改角色部门中间表
     */
    @Override
    public void updateRoleDept(SysRole sysRole) {
        //先根据角色id删除
        baseMapper.deleteByRoleId(sysRole.getRoleId());

        //保存角色和菜单的关系
        baseMapper.saveDeptRole(sysRole);
    }


}
